<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>忘记密码</title>
	<link rel="stylesheet" type="text/css" href="/build/css/base.css"/>
	<link rel="stylesheet" type="text/css" href="/build/css/main.css">
	<script src="/build/js/jquery.min.js"></script>
	<script src="/build/public/vue.js" charset="utf-8"></script>
	<script src="/build/public/vue-resource.js" charset="utf-8"></script>
	<script src="/build/js/config.js"></script>
	<script src="/build/js/common.js"></script>
	<script src="/build/js/global.js"></script>
</head>
<body style="background:#fff;">
	<div id="container" style="padding-bottom:50px;">
		<form action="" name="forms">
			<div class="password-con">
				<div class="pass-iconfont dis-pass">
				<input type="tel" placeholder="请输入手机号" maxlength="11" v-model='phoneNum'>
			</div>
				<div class="pass-iconfont"><input type="tel" placeholder="请输入验证码"  maxlength="6" v-model='verificationCode' style="float:left;width:60%;">
				<span class="tel-code" style="margin:15px 0 0 0;" v-on:click='send()'>发送验证码</span></div>
				<div class="pass-iconfont pass-iconfont1">
					<input type="password" placeholder="请输入新密码" v-model='Newpassword' name="password" id="password1" maxlength="18">
					<span class="iconfont" onclick='showps3()' id="icon">&#xe638;</span>
				</div>
				<div class="pass-iconfont pass-iconfont2">
					<input type="password" placeholder="请确认新密码" v-model='passwordCon' name="password2" id="password2" maxlength="18">
					<span class="iconfont" onclick='showps4()' id="icon2">&#xe638;</span>
				</div>
				<p style="display:none;" class="pass-none">两次密码输入不一致</p>
			</div>
			<div class="save-btn" id="disabled">保存</div>
			<div class="save-btn save-btn-sub" v-on:click='editLoginMobile()' style="display:none;" id="nodisabled">保存</div>
		</form>
	</div>
<script>
	var vm = new Vue({
	el:"#container",
			data:{
				phoneNum:'',
				verificationCode:'',
				Newpassword:'',
				passwordCon:'',
			},
			mounted:function(){
				this.$nextTick(function(){
					//验证登录密码
					$('#password').blur(function(event) {
						if(fomatPass(vm.password)){
						}else{
							toast('密码必须由6-18位字母与数字组成')
						}
					});
					$('#password1').blur(function(event) {
						if(fomatPass(vm.Newpassword)){
						}else{
							toast('密码必须由6-18位字母与数字组成')
						}
					});
					$('#password2').blur(function(event) {
						if(fomatPass(vm.passwordCon)){
						}else{
							toast('密码必须由6-18位字母与数字组成')
						}
					});
				});
			},
			methods:{
				//发送验证码
				//vm.phoneNum
				send:function(){
					if($('.tel-code').css('color')!='rgb(102, 102, 102)'){
						post('/user/send/mobile-code',{mobile:vm.phoneNum,check:true,registerCheck:false},function(res){
							$('.tel-code').css({'background':'#eee',color:'#666'});
							toast('验证码已发送，请注意查收')
							$('.password-send').css({'background':'#999',color:'#fff','border':'1px solid #999'});
							var validCode=true;
							if (validCode) {
								validCode=false;
								var time=60;
								var t=setInterval(function() {
									time--;
									$(".tel-code").html(time+"S后再次发送");
									if (time==0) {
										clearInterval(t);
									$(".tel-code").removeAttr('disabled').html("重新获取");
									$('.password-send').removeAttr('disabled').html("重新获取");
									$('.tel-code').css({'background':'rgba(0,93,158,0.2)','color':'#005d9e'});
									$('.password-send').css({'background':'rgba(0,93,158,0.2)','color':'#005d9e','border':'1px solid #005d9e'});
										validCode=true;
									}
								},1000)
							}
						})
					}
				},
				editLoginMobile:function(){
					post('/user/mobile/authentication',{mobile:vm.phoneNum,verificationCode:vm.verificationCode},function(res){
						if(res.code=='OK'){
							post('/user/mobile/reset/password',{mobile:vm.phoneNum,password:vm.Newpassword},function(res){
								toast('保存成功');
								window.localStorage.removeItem('X-Auth-Token');
      							window.localStorage.removeItem('password');
								setTimeout("window.location.href='/pages/login/login.html'",1000);
							});
						}
					});
				},
			},
		})

</script>
</body>
</html>
